//权限设置
import { router } from '../router'
import store from '@/store'
import { Message } from 'element-ui'
import { getSession } from '@/utils/session'
router.beforeEach(async (to, from, next) => {
	const whiteList = ['404', 'login', 'register'];
	let token = getSession('authorization') || null;
	if (!token) {
		if (!whiteList.some(n => n === to.name)) {
			next('/login');
			return false;
		} else {
			next();
			return false;
		}
	} else {
		if (!store.state.menuManage.ifChange) {
			const hebing = true
			await store.dispatch('getTbMenuQueryData', hebing)
			next({ ...to, replace: true })
			return false;
		} else {
			next();
			return false;
		}
	}
	/* if (token) {
		if (to.path.indexOf('/login') != -1 || to.path.indexOf('/register') != -1) {
			next(false)
		} else {
			if (!store.state.menuManage.ifChange) {
				const hebing = true
				await store.dispatch('getTbMenuQueryData', hebing)
				next({ ...to, replace: true })
			} else {
				next()
			}
		}
	} else {
		if (to.path.indexOf('/admin') != -1 || to.path.indexOf('/user') != -1) {
			Message({
				message: '您没有登录或者登录失效，请重新登录',
				type: 'warning',
			})
			next({ path: '/login?redirect=' + to.name })
		} else {
			next()
		}
	} */
})